var express = require('express');
var router = express.Router();

const {getAllUsers2,getUnnamedUsers2,getuser2,getUnpassUsers2,getOneUser2,pass2,login2}=require("../service/usersService")

/* 获取所有已注册用户加分页数据 */
router.get('/getAllUsers',async(req,res,next)=>{
  res.send(await getAllUsers2(req.query));
})

// 获取未审核的用户分页数据
router.get('/getUnnamedUsers',async(req,res,next)=>{
  res.send(await getUnnamedUsers2(req.query));
})

// 获取未审核的用户分页数据
router.get('/getUnpassUsers',async(req,res,next)=>{
  res.send(await getUnpassUsers2(req.query));
})
// 获取某一用户数据
router.get('/getOneUser',async(req,res,next)=>{
  res.send(await getOneUser2(req.query));
  console.log(req.query)
})

//审核用户
router.put('/pass',async(req,res,next)=>{
  res.send(await pass2(req.body));
})

router.get('/getuser',async(req,res,next)=>{
  res.send(await getuser2(req.query));
})

//用户登录
router.post('/login',async(req,res,next)=>{
  const data = await login2(req.body);
  if (data.length > 0) {
		req.session.currentuser = data[0].account;
		res.send(true);
	} else {
		res.send(false);
	}
})
//判断是否登录
router.get("/islogin", (req, res, next) => {
	const { currentaduser } = req.session;
	if (currentadmin) {
		res.send({ islogin: true, currentaduser });
	} else {
		res.send({
			islogin: false,
		});
	}
});


//用户注册
router.post('/regist',async (req,res,next)=>{
  res.send(await regist2(req.body));
})

module.exports = router;
